package com.android.boncen.commonFrame.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.boncen.commonFrame.MyApplication;
import com.android.boncen.commonFrame.R;
import com.android.boncen.commonFrame.bean.CommentBean;
import com.android.boncen.commonFrame.bean.DoctorBean;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * 功能描述:回复
 *
 * @date 2017/2/8
 */

public class AnswerAdapter extends BaseAdapter {

    private LayoutInflater inflater;

    public void setData(List<CommentBean> data) {
        this.data.addAll(data);
        this.notifyDataSetChanged();
    }

    public List<CommentBean> data = new ArrayList<>();

    public AnswerAdapter(Context context) {
        super();
        inflater = LayoutInflater.from(context);


    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public CommentBean getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHond hond = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.answer_item, parent, false);
            hond = new ViewHond();
            hond.tvName = (TextView) convertView.findViewById(R.id.tvName);
            hond.tvAnswer = (TextView) convertView.findViewById(R.id.tvAnswer);
            hond.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
            hond.ivHead = (ImageView) convertView.findViewById(R.id.ivHead);
            convertView.setTag(hond);

        } else {
            hond = (ViewHond) convertView.getTag();
        }
        final CommentBean bean = getItem(position);

        hond.tvTime.setText (bean.getCreatedAt ());
        hond.tvAnswer.setText (bean.getContent ());
        hond.tvName.setText (bean.getUser ().getName ());
        x.image().bind(hond.ivHead, bean.getUser ().getImage(), MyApplication.getImageOptions());

        return convertView;
    }


    static class ViewHond {
        ImageView ivHead;
        TextView tvName;
        TextView tvAnswer;
        TextView tvTime;
    }


}
